
package com.market.dao;

import java.util.List;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.market.bean.Subnews;
import com.market.dao.hibernate.GenericDaoHibernate;

/**
 * Data access object (DAO) for domain model class Subnews.
 * 
 * @see com.market.bean.Subnews
 * @author MyEclipse - Hibernate Tools
 */
public class SubnewsDAO extends  GenericDaoHibernate<Subnews, Long>
{

    public SubnewsDAO()
    {
        super();
    }
    
    public SubnewsDAO(Class<Subnews> persistentClass)
    {
        super(persistentClass);
        // TODO Auto-generated constructor stub
    }

    private static final Logger log = LoggerFactory.getLogger(SubnewsDAO.class);

    // property constants

    protected void initDao()
    {
        // do nothing
    }

    public Subnews save(Subnews transientInstance)
    {
        log.debug("saving Subnews instance");
        try
        {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        }
        catch (RuntimeException re)
        {
            log.error("save failed", re);
            throw re;
        }
        return transientInstance;
    }

    public void delete(Subnews persistentInstance)
    {
        log.debug("deleting Subnews instance");
        try
        {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        }
        catch (RuntimeException re)
        {
            log.error("delete failed", re);
            throw re;
        }
    }

    public Subnews findById(java.lang.Long id)
    {
        log.debug("getting Subnews instance with id: " + id);
        try
        {
            Subnews instance = (Subnews)getHibernateTemplate().get("com.market.bean.Subnews", id);
            return instance;
        }
        catch (RuntimeException re)
        {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findByExample(Subnews instance)
    {
        log.debug("finding Subnews instance by example");
        try
        {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        }
        catch (RuntimeException re)
        {
            log.error("find by example failed", re);
            throw re;
        }
    }

    public List findByProperty(String propertyName, Object value)
    {
        log.debug("finding Subnews instance with property: " + propertyName + ", value: " + value);
        try
        {
            String queryString = "from Subnews as model where model." + propertyName + "= ?";
            return getHibernateTemplate().find(queryString, value);
        }
        catch (RuntimeException re)
        {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    public Subnews merge(Subnews detachedInstance)
    {
        log.debug("merging Subnews instance");
        try
        {
            Subnews result = (Subnews)getHibernateTemplate().merge(detachedInstance);
            log.debug("merge successful");
            return result;
        }
        catch (RuntimeException re)
        {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Subnews instance)
    {
        log.debug("attaching dirty Subnews instance");
        try
        {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        }
        catch (RuntimeException re)
        {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(Subnews instance)
    {
        log.debug("attaching clean Subnews instance");
        try
        {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        }
        catch (RuntimeException re)
        {
            log.error("attach failed", re);
            throw re;
        }
    }

    public static SubnewsDAO getFromApplicationContext(ApplicationContext ctx)
    {
        return (SubnewsDAO)ctx.getBean("SubnewsDAO");
    }
}
